package com.mc.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mc.model.IndexImage;
import com.mc.model.Major;
import com.mc.model.Path;
import com.mc.model.data_download;
import com.mc.model.newsandbulletin;
import com.mc.service.IDataService;
import com.mc.service.IIndexImageService;
import com.mc.service.MajorService;
import com.mc.service.NewsandbulletService;
import com.mc.utils.PathUtil;
import com.mc.utils.StringUtil;

@Controller

public class IndexAction {
	
	private Path path = null;
	@Autowired NewsandbulletService newsandbulletService;
	@Autowired IDataService dataService;
	@Autowired MajorService majorService;
	@Autowired IIndexImageService indexImageService;
	/**
	 * 
	 * @param modelMap
	 * @param session
	 * @return 首页
	 */
    @RequestMapping("/index")
	public String indexui(ModelMap modelMap,HttpSession session)
	{
    	
    	List<newsandbulletin> topb = newsandbulletService.selecttopn();
    	//topb = StringUtil.getInstace().replaceTitle(topb);
    	StringUtil.getInstace().replaceTitle(topb);
    	int size;
    	if(topb==null)
    		size = 5;
    	else
    	  size = 5-topb.size();
		List<newsandbulletin> bulletins = newsandbulletService.selecttopXb(size );
		//bulletins = StringUtil.getInstace().replaceTitle(bulletins);
		StringUtil.getInstace().replaceTitle(bulletins);
    	List<newsandbulletin> newes1 = newsandbulletService.selectTopFiveNews();
    	//newes1 = StringUtil.getInstace().replaceTitle(newes1);
    	StringUtil.getInstace().replaceTitle(newes1);
    	List<newsandbulletin> zsjynewes =newsandbulletService.selectnbbytype("news", 8,0, 5);
    	//zsjynewes = StringUtil.getInstace().replaceTitle(zsjynewes);
    	StringUtil.getInstace().replaceTitle(zsjynewes);
    	modelMap.addAttribute("topb", topb);
    	modelMap.addAttribute("zsjynewes", zsjynewes);
    	modelMap.addAttribute("newes1", newes1);
    	
    	modelMap.addAttribute("bulleints", bulletins);
    	List<newsandbulletin> importantnews = newsandbulletService.selectallimportantnews();
    	session.setAttribute("importantnews", importantnews);
         List<newsandbulletin> newses = newsandbulletService.selectindexnews();
         //newses = StringUtil.getInstace().replaceTitle(newses);
         StringUtil.getInstace().replaceTitle(newses);
    	modelMap.addAttribute("newes", newses);
    	List<data_download> downlodData = dataService.selectLimit();
    	modelMap.addAttribute("downloadData",downlodData);
    	List<Major> majors = majorService.selectAllMajors();
		modelMap.addAttribute("majors",majors);
		List<IndexImage> images = indexImageService.imagesbytype(1);
		modelMap.addAttribute("images",images);
    	path = PathUtil.setPathParams(new String[]{"PackageName:index","ViewName:index","ViewTitle:西华大学数学与计算机学院-数计学院-首页","smenu:index"});				
		return PathUtil.returnStr(path, modelMap);
	}
}
